<template>
    <div id='login' class="tl-height-100-percent">
        <canvas id='canvas'
                class="tl-height-100-percent tl-width-100-percent tl-background-black tl-padding-0 tl-margin-0"></canvas>
        <div class="copy tl-text-no-select tl-pointer-events-none">&copy; Ityanger 版权所有，请保留版权标识</div>
        <div class="intro tl-text-no-select tl-pointer-events-none">
            <div class="author-first">YiShu</div>
            <div>亦舒, 一个基于SpringBoot构建的纯国产Java博客平台, 为IT极客写作而生。</div>
            <div class="author-second">--清风渡扶苏</div>
        </div>
        <el-card class="login-box silk-ribbon" style="pointer-events: none;">
            <div class="wrap">
                <span class="silk-ribbon-git tl-vh-center">
                    <a class="tl-pointer-events-auto" href="https://github.com/lzyws739307453" target="_blank">
                        <i class="iconfont icon-git"></i><span class="tl-margin-left-5">Fork Me</span>
                    </a>
                </span>
            </div>
            <!-- 头像区域 -->
            <div class="avatar-box">
                <img :src="this.$store.state.avatar_url" alt="">
            </div>
            <!-- 登录表单区域 -->
            <el-form class="login-from" ref="loginFormRef" :model="loginForm" status-icon :rules="loginFormRules">
                <el-form-item prop="username">
                    <el-input class="tl-pointer-events-auto" placeholder="请输入用户名" v-model="loginForm.username"
                              prefix-icon="iconfont icon-username"></el-input>
                </el-form-item>
                <el-form-item prop="password">
                    <el-input class="tl-pointer-events-auto" placeholder="请输入密码" v-model="loginForm.password" prefix-icon="iconfont icon-password"
                              show-password></el-input>
                </el-form-item>
                <el-row>
                    <el-col :span="7" :offset="9"><!--:loading="loading"-->
                        <el-button class="tl-pointer-events-auto" type="primary" @click="login('loginFormRef')">登 录</el-button>
                    </el-col>
                    <el-col :span="7" :offset="1">
                        <el-button class="tl-pointer-events-auto" type="info" @click="resetLoginForm('loginFormRef')">重 置</el-button>
                    </el-col>
                </el-row>
            </el-form>
        </el-card>
    </div>
</template>

<script>
import { canvas } from '@/assets/js/utils';
// import { CursorSpecialEffects } from '@/assets/js/cursor-effects';
import md5 from 'js-md5'

export default {
    name: 'Login',
    components: {},
    data: function () {
        return {
            // loading: false,
            loginForm: {
                username: 'admin',
                password: '123456'
            },
            // 表单的验证规则对象
            loginFormRules: {
                // 验证用户名是否合法
                username: [{
                    required: true, message: '请输入用户名', trigger: 'blur'
                }, {
                    min: 3, max: 16, message: '用户名长度在 3 到 16 个字符', trigger: 'blur'
                }],
                // 验证密码是否合法
                password: [{
                    required: true, message: '请输入密码', trigger: 'blur'
                }, {
                    min: 6, max: 15, message: '密码长度在 6 到 15 个字符', trigger: 'blur'
                }]
            }
        }
    },
    methods: {
        // 点击重置按钮
        resetLoginForm: function (formName) {
            this.$refs[formName].resetFields()
        },
        login: function () {
            this.$refs.loginFormRef.validate(async (valid) => {
                if (!valid) {
                    return false;
                }
                // this.loading = true;
                this.$store.dispatch('user/login', {
                    username: this.loginForm.username,
                    password: md5(this.loginForm.password)
                }).then(() => {
                    this.$message({ showClose: true, message: '恭喜你，登录成功！', type: 'success' });
                    this.$router.push({ path: this.redirect || '/admin/welcome', query: this.otherQuery })
                })
                // const { data: res } = await this.$http.post('/user/login', {
                //     username: this.loginForm.username,
                //     password: md5(this.loginForm.password)
                // });
                // console.log(res)
                // if (res.code ^ 200) {
                //     this.$message({ showClose: true, message: '登录失败，请检查用户名和密码是否正确！', type: 'error' });
                //     // this.$message({ showClose: true, message: res.msg, type: 'error' });
                // } else {
                //     this.$message({ showClose: true, message: '恭喜你，登录成功！', type: 'success' });
                //     const parse = JSON.parse(res.data);
                //     // 保存token
                //     localStorage.setItem('JWT_TOKEN', parse.token);
                //     console.log(parse.user)
                //     // 保存用户
                //     this.$store.commit('setUserInfo', parse.user);
                //     // 跳转到/admin
                //     await this.$router.push('/admin')
                // }
                // this.loading = false;
            });
        }
    },
    created: function () {
        // new CursorSpecialEffects().init()
    },
    mounted () {
        canvas();
    }
}
</script>

<style lang='less' scoped>
.copy {
    color: rgb(215, 217, 219);
    padding: 30px;
    position: fixed;
    bottom: 0;
    width: 100%;
    text-align: center;
}

.intro {
    color: rgb(215, 217, 219);
    line-height: 1.5;
    letter-spacing: 2px;
    font-weight: bold;
    font-size: 24px;
    width: 800px;
    position: fixed;
    left: 8%;
    top: 40%;

    .author-first {
        font-size: 60px;
        //font-family: 'JetBrains Mono', serif;
    }

    .author-second {
        text-align: right;
    }
}

#canvas {
    position: absolute;
}

.wrap {
    width: 100%;
    height: 188px;
    overflow: hidden;
    position: absolute;
    top: -5px;
    left: 5px;

    &:before {
        content: '';
        border-radius: 8px 8px 0 0;
        width: 40px;
        height: 4px;
        position: absolute;
        right: 23%;
        background: #9E9E9E;
    }

    &:after {
        content: '';
        border-radius: 0 8px 8px 0;
        width: 4px;
        height: 40px;
        position: absolute;
        right: 0;
        top: 43%;
        background: #9E9E9E;
    }

    .silk-ribbon-git {
        width: 180px;
        height: 26px;
        position: absolute;
        z-index: 2;
        top: 20%;
        right: -12%;
        transform: rotate(45deg);
        -ms-transform: rotate(45deg);
        -moz-transform: rotate(45deg);
        -webkit-transform: rotate(45deg);
        -o-transform: rotate(45deg);
        /* x偏移量 | y偏移量 | 阴影模糊半径 | 阴影扩散半径 | 阴影颜色 */
        //box-shadow: 0 3px 3px -1px rgba(0, 0, 0, .3);
        /* x偏移量 | y偏移量 | 阴影模糊半径 | 阴影颜色 */
        box-shadow: 0 3px 3px rgba(0, 0, 0, .3);
        background-color: #343a40 !important;

        a {
            color: #fff;
            text-shadow: 0 -1px 0 rgba(0, 0, 0, .4);
            font-size: 1.25rem;
            text-decoration: none;
        }
    }
}

::v-deep ::-ms-reveal {
    display: none;
}

.login-box {
    overflow: visible;
    width: 360px;
    //height: 460px;
    background-color: white;
    position: fixed;
    left: 65%;
    top: 25%;
}

.login-from {
    padding: 20px;

    ::v-deep .el-input--prefix .el-input__inner {
        padding-left: 25px;
    }
}

.avatar-box {
    height: 130px;
    width: 130px;
    margin: auto;
    padding: 10px;
    border: 1px solid #eee;
    border-radius: 50%;
}

.avatar-box img {
    height: 100%;
    width: 100%;
    border-radius: 50%;
    background-color: #eee;
}
</style>
